package com.AnywheeBt;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<? extends Map<String, ?>> mListData=null;
	private int nlayoutID = 0;
	private int  selectItem=-1;
	 
	public class ViewHolder {	
		ImageView   imgView;
		TextView    titleText;
		TextView 	nameText; 
		TextView 	textText; 
	}  
	//public MyAdapter(Context context, List<? extends Map<String, ?>> data,
	//		int resource, String[] from, int[] to) {	
	//	mInflater = LayoutInflater.from(context);    
	//	mListData=data;
	//	mStrForm=from;
	//	mIntTo=to;
	//}
	public MyAdapter(Context context, List<? extends Map<String, ?>> data,int resource) {	
		mInflater = LayoutInflater.from(context);    
		mListData=data;
		nlayoutID = resource;
	}
	
	@Override
	public int getCount() {
		if( mListData!=null ) return mListData.size();
		return 0;
		
	}

	@Override
	public Object getItem(int position) {
		return mListData.get(position);    
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;                
		if (convertView == null) {  
			holder = new ViewHolder();    
			convertView = mInflater.inflate(nlayoutID, null);	
//			holder.imgView=    (ImageView) convertView.findViewById(R.id.item_image);
			holder.titleText = (TextView) convertView.findViewById(R.id.call_list_name);
			holder.textText = (TextView) convertView.findViewById(R.id.call_list_text);	
//			holder.nameText = (TextView) convertView.findViewById(R.id.item_name);
			convertView.setTag(holder);             
		} else {    
			holder = (ViewHolder) convertView.getTag();  
		}   
//		if (position == selectItem) {    
//			convertView.setBackgroundResource(R.drawable.bt_num);
//		}  else {    
//			convertView.setBackgroundResource(R.drawable.bt_num_n);
//		}
		if (mListData!=null&&mListData.size()>0){			
//			holder.imgView.setImageResource( (Integer) mListData.get(position).get("item_image"));
			holder.titleText.setText( (CharSequence) mListData.get(position).get("call_list_name") );
			if(mListData.get(position).get("call_list_name").equals(""))
			{
				holder.titleText.setText(R.string.unknown);
			}
//			holder.nameText.setText( "    "+(CharSequence) mListData.get(position).get("item_name") );
			holder.textText.setText( (CharSequence) mListData.get(position).get("call_list_text") );			
		}				 
		return convertView;    
	}
	
	public  void setSelectItem(int selectItem) {     
		this.selectItem = selectItem;    
	}  
}
